/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FormBuilder.java
 *
 * Created on Aug 25, 2011, 4:05:36 PM
 */
package employeemanagement;

/**
 *
 * @author pruthadesai
 */
public class FormBuilder extends javax.swing.JFrame {

    int choice = 0;
    private String empId = "";
    private String empName = "";
    private String empEmail = "";
    private int empSSN = 0;
    private int empLevel = 1;
    /** Creates new form FormBuilder */
    public FormBuilder() {
        initComponents();
    }

    public FormBuilder(int c){
        initComponents();
        this.choice = c;
        this.empId = "";
        this.empName = "";
        this.empEmail = "";
        this.empSSN = 0;
        this.empLevel = 1;
        System.out.println("Your choice is "+c);
        setVisible(true);
        
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        txtemail = new javax.swing.JTextField();
        lblName = new javax.swing.JLabel();
        lblemail = new javax.swing.JLabel();
        lblssn = new javax.swing.JLabel();
        txtName = new javax.swing.JTextField();
        txtSsn = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        rblevel1 = new javax.swing.JRadioButton();
        rblevel2 = new javax.swing.JRadioButton();
        rblevel3 = new javax.swing.JRadioButton();
        okEmployeeForm = new javax.swing.JButton();
        lblEmpId = new javax.swing.JLabel();
        txtEmpId = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "DesignPatterns Inc.", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Gabriola", 1, 24))); // NOI18N

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Employee Personal Details", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Lucida Grande", 0, 16), new java.awt.Color(0, 0, 255))); // NOI18N

        txtemail.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, new java.awt.Color(0, 51, 204), null, null, new java.awt.Color(0, 51, 204)));
        txtemail.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtemailActionPerformed(evt);
            }
        });

        lblName.setText("Name");

        lblemail.setText("SSN Id:");

        lblssn.setText("Email Id:");

        txtName.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, new java.awt.Color(0, 51, 204), null, null, new java.awt.Color(0, 51, 204)));
        txtName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNameActionPerformed(evt);
            }
        });

        txtSsn.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, new java.awt.Color(0, 51, 204), null, null, new java.awt.Color(0, 51, 204)));
        txtSsn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtSsnActionPerformed(evt);
            }
        });

        jLabel1.setText("Select Level");

        rblevel1.setText("Level1");
        rblevel1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rblevel1ActionPerformed(evt);
            }
        });

        rblevel2.setText("Level2");
        rblevel2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rblevel2ActionPerformed(evt);
            }
        });

        rblevel3.setText("Level3");
        rblevel3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rblevel3ActionPerformed(evt);
            }
        });

        okEmployeeForm.setText("Next");
        okEmployeeForm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okEmployeeFormActionPerformed(evt);
            }
        });

        lblEmpId.setText("Employee Id");

        txtEmpId.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, new java.awt.Color(0, 51, 204), null, null, new java.awt.Color(0, 51, 204)));
        txtEmpId.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtEmpIdActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(okEmployeeForm))
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(40, 40, 40)
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel2Layout.createSequentialGroup()
                                .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 85, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(45, 45, 45)
                                .add(rblevel1)
                                .add(18, 18, 18)
                                .add(rblevel2)
                                .add(18, 18, 18)
                                .add(rblevel3))
                            .add(jPanel2Layout.createSequentialGroup()
                                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(lblEmpId)
                                    .add(lblName)
                                    .add(lblssn)
                                    .add(lblemail, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 44, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .add(26, 26, 26)
                                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(txtSsn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 337, Short.MAX_VALUE)
                                    .add(txtEmpId, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 337, Short.MAX_VALUE)
                                    .add(txtName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 337, Short.MAX_VALUE)
                                    .add(txtemail, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 337, Short.MAX_VALUE))))))
                .add(160, 160, 160))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(31, 31, 31)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(lblEmpId)
                    .add(txtEmpId, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 30, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(28, 28, 28)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(txtName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 30, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(lblName))
                .add(33, 33, 33)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(txtemail, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 29, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(lblssn))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 28, Short.MAX_VALUE)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(txtSsn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 32, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(lblemail))
                .add(18, 18, 18)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(rblevel1)
                    .add(rblevel2)
                    .add(rblevel3))
                .add(18, 18, 18)
                .add(okEmployeeForm)
                .add(68, 68, 68))
        );

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(12, 12, 12)
                .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(28, 28, 28))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(8, 8, 8)
                .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(47, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void txtemailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtemailActionPerformed
    empEmail += txtemail.toString();
}//GEN-LAST:event_txtemailActionPerformed

private void txtNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNameActionPerformed
    empName += txtName.toString();
}//GEN-LAST:event_txtNameActionPerformed

private void txtSsnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtSsnActionPerformed
    empSSN += Integer.parseInt(txtSsn.toString());
}//GEN-LAST:event_txtSsnActionPerformed

private void rblevel1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rblevel1ActionPerformed
    empLevel = 1;
}//GEN-LAST:event_rblevel1ActionPerformed

private void rblevel2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rblevel2ActionPerformed
    empLevel = 2;
}//GEN-LAST:event_rblevel2ActionPerformed

private void rblevel3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rblevel3ActionPerformed
    empLevel = 3;
}//GEN-LAST:event_rblevel3ActionPerformed

private void okEmployeeFormActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okEmployeeFormActionPerformed
    
    setVisible(false);
    empEmail = txtemail.getText();
    empName = txtName.getText();
    empId = txtEmpId.getText();
    empSSN = Integer.parseInt(txtSsn.getText());
    
    System.out.println(empId +"**"+ empName +"**"+ empEmail +"**"+ empSSN +"**"+ empLevel);
    
    AbstractFormBuilder ab = new ConcreteFormBuilder(empLevel, empId, empName, empEmail, empSSN);
    
    if(choice == 1){
        ab.buildForm();
    }else
        ab.buildForm(choice);
}//GEN-LAST:event_okEmployeeFormActionPerformed

private void txtEmpIdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtEmpIdActionPerformed
    empId = txtEmpId.toString();
}//GEN-LAST:event_txtEmpIdActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FormBuilder.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FormBuilder.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FormBuilder.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FormBuilder.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new FormBuilder().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JLabel lblEmpId;
    private javax.swing.JLabel lblName;
    private javax.swing.JLabel lblemail;
    private javax.swing.JLabel lblssn;
    private javax.swing.JButton okEmployeeForm;
    private javax.swing.JRadioButton rblevel1;
    private javax.swing.JRadioButton rblevel2;
    private javax.swing.JRadioButton rblevel3;
    private javax.swing.JTextField txtEmpId;
    private javax.swing.JTextField txtName;
    private javax.swing.JTextField txtSsn;
    private javax.swing.JTextField txtemail;
    // End of variables declaration//GEN-END:variables
}
